package com.snapan.service.impl;

import com.snapan.common.PageResult;
import com.snapan.dao.RecycleDao;
import com.snapan.entity.UserFile;
import com.snapan.service.RecycleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Service
@Transactional
public class RecycleServiceImpl implements RecycleService {
    @Autowired
    private RecycleDao recycleDao;
    @Override
    public PageResult<UserFile> selectByPage(int pageSize, int pageNo, int userId, int parentId) {
        // 1. 计算偏移量（分页查询的起始位置）
        int offset = (pageNo - 1) * pageSize;

        // 2. 查询核心数据：当前页列表 + 总记录数
        List<UserFile> fileList = recycleDao.selectByPage(offset, pageSize, userId, parentId); // 当前页数据
        long total = recycleDao.countByCondition(userId, parentId); // 符合条件的总记录数
        return PageResult.of(pageNo, pageSize, total, fileList);
    }

    @Override
    public Integer restore(Long id) {
        return recycleDao.restore(id);
    }

    @Override
    public Integer permanentDelete(Long id) {
        return recycleDao.permanentDelete(id);
    }
}
